package com.itheima.health.service.impl;

import com.itheima.health.dao.OrderDao;
import com.itheima.health.dao.SetmeaDao;
import com.itheima.health.pojo.Order;
import com.itheima.health.pojo.UserOrder;
import com.itheima.health.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 预约下单
 */
@Service
@Slf4j
public class OrderServicelmpl implements OrderService {
    @Autowired
    private OrderDao orderDao;
    @Autowired
    private SetmeaDao setmeaDao;

    /**
     * 添加预约信息
     *
     * @param userOrder
     */
    public void addOrder(UserOrder userOrder) {
        orderDao.addOrder(userOrder);
        Integer orderId = orderDao.getLastInsertId();
        Order order = new Order();
        order.setMember(userOrder.getName());
        order.setOrderDate(userOrder.getOrderDate());
        order.setOrderType(Order.ORDERTYPE_WEIXIN);
        order.setId(userOrder.getId());
        order.setSetmealId(userOrder.getSetmealId());
        order.setOrderId(orderId);
        order.setSetmeal(setmeaDao.findById(order.getSetmealId()).getName());
        orderDao.add(order);

        userOrder.setId(orderId);

    }

    /**
     * 根据orderId查询预订信息
     * @param id
     * @return
     */
    public Order findById(Integer id) {
        return orderDao.findById(id);
    }
}
